package com.wc.codeforces.二分.Substring_and_Subsequence;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/6/27 22:54
 * @description https://codeforces.com/contest/1989/problem/B
 */
public class Main {
    /**
     * 思路：
     * 由题可知b中的连续子串  一定是a的子序列才满足最小的
     * 直接二分枚举b中的子串, 看这个长度是否是a的子序列, 这个用的双指针
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 110;
    // f[i][j] 表示 s的第i个位置相等与t的第j个位置相等的最长值
    static char[] s, t;
    static int T, n, m;

    public static void main(String[] args) {
        T = sc.nextInt();
        while (T-- > 0) {
            s = (" " + sc.next()).toCharArray();
            t = (" " + sc.next()).toCharArray();
            n = s.length - 1;
            m = t.length - 1;
            int l = 0, r = m;
            while (l < r) {
                int mid = l + r + 1 >> 1;
                if (check(mid)) l = mid;
                else r = mid - 1;
            }

            out.println(n + m - l);
        }
        out.flush();
    }

    static boolean check(int len) {
        for (int l = 1; l + len - 1 <= m; l++) {
            int r = l + len - 1;
            int j = l;
            for (int i = 1; i <= n; i++) {
                if (s[i] == t[j]) j++;
                if (j == r + 1) return true;
            }
        }

        return false;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
